/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.dao.impl;

import com.qdu.dao.BaseDao;
import com.qdu.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;



public class BaseDaoImpl implements BaseDao {

    @Override
    public int executeUpdate(String sql, Object... params) {
        Connection con = null;
        PreparedStatement ps = null;
        int rows = 0; //受影响行数

        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement(sql);
            int i =1;
            for (Object o : params) {
                ps.setObject(i, o);
                i++;    
            }
            rows = ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(null, ps, con);
        }
        return rows;
    }

}
